package cn.itsource.service.impl;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.itsource.api.LoginRemoteApi;
import cn.itsource.constants.ErrorCode;
import cn.itsource.mapper.LoginMapper;
import cn.itsource.pojo.domain.Login;
import cn.itsource.result.JSONResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program fccar
 * @Author luoc
 * @Date 2024/09/03 17:21
 * @Version 1.0.0
 * @Description
 */
@RestController
public class RegisterServiceImpl implements LoginRemoteApi {

    @Autowired
    private LoginMapper loginMapper;

    @Override
    @SaIgnore
    public JSONResult register(Login login) {
        LambdaQueryWrapper<Login> wrapper = new LambdaQueryWrapper<Login>().eq(Login::getId, login.getId());
        Login login1 = loginMapper.selectOne(wrapper);
        if (login1 == null) {
            loginMapper.insert(login);
            return JSONResult.success();
        }
        return JSONResult.error(ErrorCode.PARAM_PHONE_EXIST);
    }
}
